//
//  CreateFileController.swift
//  Unzip
//
//  Created by zhibao on 2024/7/15.
//

import UIKit
import SnapKit

@objc class ToolsController:SuperController{
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.initView()
        self.gk_navTitle = LocalizedString("工具")
    }
    
    private func initView(){
        let xianchangTitles = [
            [
                "title":LocalizedString("现场录音"),
                "color":"#ff8070",
                "img":"waveform"
            ],
            [
                "title":LocalizedString("现场录像"),
                "color":"#50C17A",
                "img":"livephoto"
            ],
            [
                "title":LocalizedString("现场拍照"),
                "color":"#FF8825",
                "img":"video"
            ],
        ]
        
        var tempView:UIView?
        for i in 0 ..< xianchangTitles.count {
            let btn = UIButton(type: .custom)
            btn.layer.cornerRadius = pixw(p: 20)
            btn.tintColor = UIColor.white
            btn.backgroundColor = MYColor.color(withHexString: xianchangTitles[i]["color"]!)
            btn.setTitle(xianchangTitles[i]["title"], for: .normal)
            btn.titleLabel?.font = MY_SCALE_BoldFont(15)
            btn.setImage(UIImage(systemName: xianchangTitles[i]["img"]!), for: .normal)
            btn.setButtonImageAlignmentStyle(.top, imageAndLabelSpace: pixw(p: 10))
            btn.tag = 1000 + i
            btn.addTarget(self, action: #selector(btnClick(sender: )), for: .touchUpInside)
            self.view.addSubview(btn)
            btn.snp.makeConstraints { make in
                make.left.equalTo(pixw(p: 50))
                make.right.equalTo(pixw(p: -50))
                make.height.equalTo(pixw(p: 130))
                if tempView == nil {
                    make.top.equalTo(navigationFullHeight() + pixw(p: 100))
                }else{
                    make.top.equalTo(tempView!.snp.bottom).offset(pixw(p: 20))
                }
            }
            tempView = btn
        }
    }
    
    @objc fileprivate func btnClick(sender:UIButton){
        let flag = MYGlobal.share().isVip()
        if(flag == false){
            Helper.alertShow(withTitle: LocalizedString("提示"), withContent: LocalizedString("您不是VIP会员，暂时无法使用该功能！点击去看看解锁该功能！"), withSureBtnTitle: LocalizedString("去看看"), withCancelBtnTitle: LocalizedString("取消")) { index in
                //去往购买中心
                if index == 1 {
                    let controller = PayMarkController()
                    self.navigationController?.pushViewController(controller, animated: true)
                }
            }
            return
        }
        if sender.tag == 1000 {
            //录音
            let controller = RecordListController()
            self.navigationController?.pushViewController(controller, animated: true)
        }else if sender.tag == 1001 {
            //录像
            let controller = LuXiangController()
            self.navigationController?.pushViewController(controller, animated: true)
        }else if sender.tag == 1002 {
            //拍照
            let controller = PaizhaoController()
            self.navigationController?.pushViewController(controller, animated: true)
        }
    }
}
